package com.zdemo.factors;

import java.math.BigInteger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Tester {

	public static void main(String[] args) {
		test2();
	}
	
	public static void test1() {
		ExecutorService exec = Executors.newFixedThreadPool(1000);
		final VolatileFactorHandler volatileFactorHandler = new VolatileFactorHandler();
		for (int i = 0; i < 1000; i++) {
			Runnable r = new Runnable() {
				@Override
				public void run() {
					int random = (int) (Math.random() * 100 + 1);
					BigInteger[] factors = volatileFactorHandler.handle(BigInteger.valueOf(random));
					if(random != factors[0].intValue()) {
						System.out.println("number:" + random + ", factors:" + factors[0].intValue());
					} else {
						System.out.println(".");
					}
				}
			};
			exec.submit(r);
		}
	}
	
	public static void test2() {
		ExecutorService exec = Executors.newFixedThreadPool(1000);
		final UnsafeFactorHandler handler = new UnsafeFactorHandler();
		for (int i = 0; i < 1000; i++) {
			Runnable r = new Runnable() {
				@Override
				public void run() {
					int random = (int) (Math.random() * 100 + 1);
					BigInteger[] factors = handler.handle(BigInteger.valueOf(random));
					if(random != factors[0].intValue()) {
						System.out.println("number:" + random + ", factors:" + factors[0].intValue());
					} else {
						System.out.println(".");
					}
				}
			};
			exec.submit(r);
		}
	}
}
